package com.sfac.cqlg.controller;

import com.sfac.cqlg.entity.Result;
import com.sfac.cqlg.entity.User;
import com.sfac.cqlg.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * UserController
 */
@RestController

// 公共路劲
@RequestMapping("/api")
public class UserController {

    // 注入
    @Autowired
    private UserService userService;

    /**
     * 127.0.0.1:8080/api/user ---- post
     * {"userName":"hj1","password":"111111"}
     */
    @PostMapping(value = "/user",consumes = "application/json")
    public Result<User> insertUser(@RequestBody User user) {
        return userService.insertUser(user);
    }

    /**
     * 127.0.0.1:8080/api/login ---- post
     * {"userName":"hj1","password":"111111"}
     */
    @PostMapping(value="/login",consumes = "application/json")
    public Result<User> login(@RequestBody User user) {
        return userService.login(user);
    }

}
